package com.zzyl.service.impl;


import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDTO;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class NursingLevelServiceImpl implements NursingLevelService {

    @Autowired
    private NursingLevelMapper nursingLevelMapper;


    @Override
    public List<NursingLevelDTO> selectAll() {
        List<NursingLevel> nursingLevelList = nursingLevelMapper.selectAll();
        return BeanUtil.copyToList(nursingLevelList, NursingLevelDTO.class);
    }

    @Override
    public void add(NursingLevelDTO nursingLevelDTO) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDTO, NursingLevel.class);
        nursingLevelMapper.insert(nursingLevel);
    }

    @Override
    public PageResponse<NursingLevelVO> getByPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingLevel>  nursingLevelPage = nursingLevelMapper.selectByPage(name, status);
        return PageResponse.of(nursingLevelPage, NursingLevelVO.class);
    }

    @Override
    public NursingLevelVO getById(Long id) {
        NursingLevel nursingLevel = nursingLevelMapper.selectByPrimaryKey(id);
        return BeanUtil.toBean(nursingLevel, NursingLevelVO.class);
    }

    @Override
    public void update(NursingLevelDTO nursingLevelDTO) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDTO, NursingLevel.class);
        nursingLevelMapper.updateByPrimaryKey(nursingLevel);
    }

    @Override
    public void delete(Long id) {
        nursingLevelMapper.deleteByPrimaryKey(id);
    }
}